//
//  orderTableViewCell.m
//  随便点
//
//  Created by MWJ on 15/3/16.
//  Copyright (c) 2015年 qfsoft. All rights reserved.
//

#import "orderTableViewCell.h"
#import "AppDelegate.h"
#import "OrderCheckViewController.h"
#import "PingJiaViewController.h"
#import "psztViewController.h"

@implementation orderTableViewCell{
    AppDelegate *delegate;
    NSString *str;
    NSString *str1;
    NSDictionary *dic;
}

- (void)awakeFromNib {
    [self.button1 addTarget:self action:@selector(queren)  forControlEvents :UIControlEventTouchUpInside];
    [self.button2 addTarget:self action:@selector(peisongzt) forControlEvents:UIControlEventTouchUpInside];
    // Initialization code
}
-(void)queren{
    if ([self._state.text isEqualToString:@"等待"]) {
        delegate  = (AppDelegate *)[[UIApplication sharedApplication]delegate];
        [delegate haveView];
        UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
        OrderCheckViewController *ocvc = [sb instantiateViewControllerWithIdentifier:@"orderCheck"];
        if ([self.qbddid isEqualToString:@""]||self.qbddid == nil) {
            delegate.querId= self.ID;
            NSLog(@"pj%@",delegate.querId);
        }else{
            delegate.querId = self.qbddid;
            NSLog(@"pj%@",delegate.querId);
        }
        [delegate.haveView pushViewController:ocvc animated:YES];
//        NSLog(@"idshi%@",delegate.querId);
    }else if ([self._state.text isEqualToString:@"取消"]){
        str = @"http://www.51anys.com:8080/waimaiwang/order/cancel/";
        str1 = [NSString stringWithFormat:@"%@%@",str,self.qbddid];
        NSURL *url=[NSURL URLWithString:str1];
        NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:url];
        NSString *postStr=@"";
        [request setHTTPMethod:@"post"];
        NSData *data=[postStr dataUsingEncoding:NSUTF8StringEncoding];
        [request setHTTPBody:data];
        [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError){
            dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil];
            [self performSelectorOnMainThread:@selector(refreshData:) withObject:dic waitUntilDone:YES];
        }];
        self.button1.hidden = YES;
        self._state.text = @"作废";
        
    }else if ([self._state.text isEqualToString:@"已完成"]){
        delegate  = (AppDelegate *)[[UIApplication sharedApplication]delegate];
        [delegate haveView];
        UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
        PingJiaViewController *pj = [sb instantiateViewControllerWithIdentifier:@"pjVC"];
        if ([self.pjddid isEqualToString:@""]||self.pjddid == nil) {
            delegate.dpname = self.qbdianming;
            delegate.dppic = self.qbqbtp;
            delegate.DDID = self.qbddid;
            NSLog(@"pj%@",delegate.DDID);
        }else{
        delegate.dpname = self.pjdianming;
        delegate.dppic = self.pjdbtp;
        delegate.DDID = self.pjddid;
        }
        [delegate.haveView pushViewController:pj animated:YES];
        
        NSLog(@"444444");
        
    }else{
        
        
    }
}
-(void)refreshData:(NSArray *)sender{
}
-(void)peisongzt{
    delegate  = (AppDelegate *)[[UIApplication sharedApplication]delegate];
    [delegate haveView];
    if (self.qbddid == nil||[self.qbddid isEqualToString:@""]) {
        delegate.psid = self.pjddid;
    }else{
    delegate.psid = self.qbddid;
    }
    NSLog(@"psdi%@",delegate.psid);
    UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    psztViewController *pszt = [sb instantiateViewControllerWithIdentifier:@"psztVC"];
    [delegate.haveView pushViewController:pszt animated:YES];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
